﻿using AutoMapper;
using DFGK.IRepository;
using DFGK.IService;
using DFGK_WMS.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yitter.IdGenerator;

namespace DFGK.Service
{
    public class EmployeeService : BaseService, IEmployeeService
    {
        private readonly IEmployeeRepository employeeRepository;
        private readonly IDepartMentRepository departMentRepository;
        private readonly IUnitOfWork unitOfWork;
        public EmployeeService(IMapper mapper, IEmployeeRepository employeeRepository, IDepartMentRepository departMentRepository, IUnitOfWork unitOfWork) : base(mapper)
        {
            this.employeeRepository = employeeRepository;
            this.departMentRepository = departMentRepository;
            this.unitOfWork = unitOfWork;
        }

        public bool AddEmployeeList(List<Employee> employee,out string message)
        {
             message = string.Empty;
            foreach (var item in employee)
            {
                item.Id = YitIdHelper.NextId();
                var employees = employeeRepository.QueryIsEntityWhere(x => x.EmployeeCode == item.EmployeeCode);
                if (employees != null)
                {
                    message = $"{item.EmployeeCode}编码已存在";
                    return false;
                   
                }
               
            }
            employeeRepository.AddEntityList(employee);
            return unitOfWork.SaveChangesEntity();
        }
    }
}
